#include <stdarg.h>
#include <stdio.h>
#include "socket.h"
#include "game_version.h"
#include "game_log.h"
#include "game_http.h"
#include <string.h>
#include "game_macros.h"
#include <unistd.h>
#include "game_ev.h"

CGame::Logger::StdoutLoggerFactory g_LoggerFactory;

CGameLoggerFactory *CGameLoggerFactory::getInstance()
{
  return &g_LoggerFactory;
}

BOOL Socket::init()
{
  _logger = CGameLoggerFactory::getInstance()->getLogger("Socket");
  _logger->info("Init Socket.");
  return CGameSocket::init();
}

void Socket::run()
{
  do{

    CGameSocket::run();
    usleep(_sleep * 1000);
  } while (true);
}



BOOL Socket::disconnect()
{
  CGameSocket::disconnect();
  _logger->info("%s", "disconnect");
  return TRUE;
}

int main()
{
  __vprint();
  __ev_config();
  int ret = 0;
  do
  {

    CC_BREAK_IF(!g_LoggerFactory.init());

    const char *dat = "abcdefg";

    Socket sd;
    // if(sd.connect("127.0.0.1",9999)){
    //   sd.send(dat,strlen(dat));
    //   sd.run();
    // }
    CC_BREAK_IF(!sd.init());
    CC_BREAK_IF(!0 >= (ret = sd.connect("127.0.0.1", 9999)));

    sd.send(dat, strlen(dat));
    sd.run();
    return 0;
  } while (true);

  return ret;
}
